package com.shilin.lanqiu;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.shilin.lanqiu.util.PlayVoice;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DataFrame extends JFrame {
    public static JTextField jTextField;
    public DataFrame(String name){
        super();
        this.setBounds(500,500,900,100);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //不可调整大小
        this.setResizable(false);
        jTextField = new JTextField();
        jTextField.setText("等待数据                                等待数据        等待数据                                等待数据");
        jTextField.setVisible(true);
        jTextField.setEditable(false);
        this.add(jTextField);
        this.setVisible(true);
    }

    public static void playAudio(String json){
        JSONObject jsonObject = JSONObject.parseObject(json);
        String mainTeam = jsonObject.getString("mainTeam");
        String passengerTeam = jsonObject.getString("passengerTeam");
        Integer voice = jsonObject.getInteger("voice");
        String file = "";
        String action = "";
        switch (voice){
            case 0:
                file = "D:\\篮球录音\\暂停比赛.mp3";
                action = "暂停比赛";
                break;
            case 21:
                file = "D:\\篮球录音\\主队犯规.mp3";
                action = "主队犯规";
                break;
            case 22:
                file = "D:\\篮球录音\\主队二罚一掷.mp3";
                action = "主队二罚一掷";
                break;
            case 23:
                file = "D:\\篮球录音\\主队没有.mp3";
                action = "主队没有";
                break;
            case 24:
                file = "D:\\篮球录音\\主队得分.mp3";
                action = "主队得分";
                break;
            case 25:
                file = "D:\\篮球录音\\主队球权.mp3";
                action = "主队球权";
                break;
            case 26:
                file = "D:\\篮球录音\\主队三分机会.mp3";
                action = "主队三分机会";
                break;
            case 27:
                file = "D:\\篮球录音\\主队二分机会.mp3";
                action = "主队二分机会";
                break;
            case 1:
                file = "D:\\篮球录音\\客队二罚一掷.mp3";
                action = "客队二罚一掷";
                break;
            case 2:
                file = "D:\\篮球录音\\客队犯规.mp3";
                action = "客队犯规";
                break;
            case 3:
                file = "D:\\篮球录音\\客队得分.mp3";
                action = "客队得分";
                break;
            case 4:
                file = "D:\\篮球录音\\客队没有.mp3";
                action = "客队没有";
                break;
            case 5:
                file = "D:\\篮球录音\\客队球权.mp3";
                action = "客队球权";
                break;
            case 6:
                file = "D:\\篮球录音\\客队二分机会.mp3";
                action = "客队二分机会";
                break;
            case 7:
                file = "D:\\篮球录音\\客队三分机会.mp3";
                action = "客队三分机会";
                break;
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        jTextField.setText(format.format(new Date())+"                                "+mainTeam+"        "+passengerTeam+"                                "+action);
        PlayVoice.run(file);
    }

}
